#include "threadpool.h"

// 获取单例实例
ThreadPool& ThreadPool::instance() {
    static ThreadPool pool;
    return pool;
}

// 启动一个任务
void ThreadPool::startTask(QRunnable* task) {
    m_threadPool.start(task);
}

// 设置最大线程数
void ThreadPool::setMaxThreadCount(int count) {
    m_threadPool.setMaxThreadCount(count);
}

// 构造函数，初始化线程池最大线程数
ThreadPool::ThreadPool(QObject* parent) : QObject(parent) {
    m_threadPool.setMaxThreadCount(QThread::idealThreadCount());
}

// 析构函数，等待所有任务完成
ThreadPool::~ThreadPool() {
    m_threadPool.waitForDone();
}
